#define _WINSOCK_DEPRECATED_NO_WARNINGS 1

#include <iostream>
#include <winsock2.h>
#include <string.h>
#include <string>
using namespace std;

#pragma comment(lib,"ws2_32.lib")

int main()
{
	//初始化winsock库
	WSADATA wsadata;
	if (WSAStartup(MAKEWORD(2, 2), &wsadata) != 0)
	{
		cerr << "Failed to initialize Winsock！" << endl;
		return 1;
	}

	//创建套接字，这里的返回值是一个整数
	SOCKET sock = socket(AF_INET, SOCK_DGRAM, 0);
	if (sock == INVALID_SOCKET)
	{
		cout << "Create Socket Fail！" << endl;
		WSACleanup();//将库清理
		return 1;
	}

	struct sockaddr_in server;
	memset(&server, 0, sizeof(server));
	server.sin_family = AF_INET;
	server.sin_addr.s_addr = inet_addr("139.9.106.117");
	server.sin_port = htons(8080);

	string msg;
	//发送
	while (1)
	{
		cout << "Please Enter# ";
		getline(cin, msg);
		int len = sendto(sock, msg.c_str(), msg.size(), 0, (struct sockaddr*)&server, sizeof server);
	}

	closesocket(sock);
	WSACleanup();
	return 0;
}